package db

import (
	"gitee.com/saxon134/go-utils/saData/saUrl"
	"gitee.com/saxon134/go-utils/saLog"
	"gitee.com/saxon134/go-utils/saOrm"
	"gitee.com/saxon134/go-utils/saOss"
	"gitee.com/saxon134/workflow/conf"
)

var MySql *saOrm.DB
var Oss saOss.SaOss

func Init() {
	var err error

	//初始化MySql数据库
	{
		var config = conf.Conf.MySql
		dsn := config.User + ":" + config.Pass + "@tcp(" + config.Host + ")/workflow" + "?charset=utf8mb4&parseTime=True&multiStatements=true&loc=Local"
		MySql = saOrm.Open(dsn, saOrm.Conf{})

		saLog.Log("[MySql] init ok")
	}

	//初始化OSS
	ossConf := conf.Conf.Oss
	Oss, err = saOss.InitOss(saOss.AliOssType, ossConf.EndPoint, ossConf.AccessKeyId, ossConf.AccessKeySecret, ossConf.Bucket)
	if err != nil {
		saLog.Err("oss初始化出错:", err)
		panic(1)
	}
	saLog.Log("[OSS] init ok")

	//初始化saUrl
	saUrl.Init(conf.Conf.Oss.Host, nil)
}
